<template>
	<div class="app-container">
		<div class="row1">
			<span class="left-label">类型</span>
			<el-select v-model="queryData.documentCategory" placeholder="请选择" size="default" clearable class="select">
				<el-option v-for="dict in document_category" :key="dict.value" :label="dict.label" :value="dict.value" />
			</el-select>
		</div>
		<div class="row3">
			<span class="left-label">关键字</span>
			<el-input v-model="queryData.documentTitle" style="width: 350px; margin-right: 20px" placeholder="请输入搜索关键字" />
			<el-checkbox style="position: relative; top: 3px" true-label="1" false-label="" v-model="queryData.isImportant" label="推荐" size="large" />
		</div>
		<div class="row2">
			<span class="left-label">更新时间</span>
			<el-date-picker
				:style="{ width: '340px' }"
				v-model="queryData.updateTime"
				value-format="YYYY-MM-DD HH:mm:ss"
				type="daterange"
				range-separator="-"
				start-placeholder="开始日期"
				end-placeholder="结束日期"></el-date-picker>
		</div>
		<div class="row4">
			<span class="left-label"></span>
			<el-button type="primary" @click="search">搜索</el-button>
			<el-button @click="reset">重置</el-button>
			<el-button @click="linkToAdd()">添加</el-button>
		</div>
		<BaseTable  v-loading="loading" :columns="columns" :dataList="dataList">
			<template #action="{ row }">
				<el-button type="primary" size="small" plain @click="toDetail(row.documentId)"
					><el-icon style="margin-right: 5px"><View /></el-icon>详情</el-button
				>
				<el-button v-if="userStore.$state.name == row.createUserCode" type="primary" size="small" plain @click="toEdit(row.documentId)"
					><el-icon style="margin-right: 5px"><Edit /></el-icon>修改</el-button
				>
				<el-button v-if="userStore.$state.name == row.createUserCode" type="primary" size="small" plain @click="deleteCus(row.documentId)"
					><el-icon style="margin-right: 5px"><CirclePlusFilled /></el-icon>删除</el-button
				>
			</template>
		</BaseTable>
		<pagination :total="total" v-model:page="queryData.pageNum" v-model:limit="queryData.pageSize" @pagination="search" />
	</div>
</template>
<script setup>
import { reactive } from 'vue'
import BaseTable from '@/components/BaseTable'
import { listDocument, delDocument } from '@/api/tank/tank'
import useUserStore from '@/store/modules/user'
const userStore = useUserStore()
console.log(userStore)
const router = useRouter()
const { proxy } = getCurrentInstance()
const { document_category } = proxy.useDict('document_category')
const prop = defineProps({
	isOpen: Boolean,
	documentTitle: String,
	customerCategory: String
})
const columns = ref([
	{ key: 1, label: `名称`, prop: 'documentTitle', type: 'text', visible: true },
	{ key: 4, width: '120', label: `类型`, prop: 'documentCategory', type: 'select', data: document_category, visible: true },
	{ key: 2, width: '150', label: `更新时间`, prop: 'updateTime', type: 'dateTimeSf', visible: true },
	{ key: 3, width: '250', label: `操作`, prop: 'action', type: 'custom', visible: true }
])
const total = ref(0)
const dataList = ref([{}])
const loading = ref(false)
const queryData = reactive({
	pageNum: 1,
	pageSize: 100,
	documentCategory: prop.customerCategory,
	updateTime: [],
	documentTitle: prop.documentTitle,
	isImportant: ''
})
const search = () => {
	let obj = { ...queryData }
	if (queryData.updateTime && typeof queryData.updateTime == 'object') {
		obj.startTime = queryData.updateTime[0]
		obj.endTime = queryData.updateTime[1]
		obj.updateTime = undefined
	}
	loading.value = true
	listDocument(obj).then((res) => {
		dataList.value = res.rows
		total.value = res.total
		loading.value = false
	})
}
search()
const reset = () => {
	for (let item in queryData) {
		queryData[item] = ''
	}
	queryData['isImportant'] = ''
	queryData.pageNum = 1
	queryData.pageSize = 1000
	queryData['updateTime'] = []
	search()
}
const linkToAdd = () => {
	router.push({
		path: '/tank/tankAdd'
	})
}
const toDetail = (id) => {
	router.push({
		path: '/tank/tankDetail',
		query: { id: id }
	})
}
const toEdit = (id) => {
	router.push({
		path: '/tank/tankEdit',
		query: { id: id }
	})
}
const deleteCus = (id) => {
	proxy.$modal
		.confirm('是否确认此操作？')
		.then(() => {
			return delDocument(id)
		})
		.then(() => {
			search()
			proxy.$modal.msgSuccess('删除成功')
		})
		.catch(() => {})
}
</script>
<style lang="scss" scoped>
.left-label {
	color: #33b6fe;
	height: 24px;
	line-height: 24px;
	position: relative;
	top: 1px;
	margin-right: 10px;
	display: inline-block;
	min-width: 80px;
}
:deep(.el-table__header) {
	background-color: #2f3f56;
}
.row1 {
	border-bottom: 1px rgba(240, 240, 240, 1) solid;
	padding: 5px 0 10px 0;
	.label {
		margin: 5px;
		padding: 8px 5px;
		font-size: 14px;
		background-color: rgb(231, 231, 231);
	}
	.select {
		width: 220px;
		position: relative;
		top: -1px;
	}
}
.row2 {
	border-bottom: 1px rgba(240, 240, 240, 1) solid;
	padding: 5px 0 10px 0;
}
.row3 {
	border-bottom: 1px rgba(240, 240, 240, 1) solid;
	padding: 5px 0 10px 0;
}
.row4 {
	padding: 5px 0 10px 0;
}
</style>
